<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp"%>
<%
    /******************************记录排班到线上数据库***********************************/

    hospital = 1113;
    //先删除部门
    QBuilder.db("basedb").execHQL("delete from Schedule where hospital = " + hospital );

    String json = HttpUtil.post("http://192.168.1.250:8080/schedule/queryAll.jsp");
    Map map = JSONUtil.mapFromJson(json);
    List<Map> list = (List<Map> )map.get("data");
    if(list == null || list.size() == 0){
        Tools.print(out,"没有从医院获取相关数据");
        return;
    }
    //添加集合
    List<Schedule> schedules = new ArrayList<Schedule>();
    for(Map mp : list){

        //预约日期
        String zxrq = mp.get("zxrq").toString();
        zxrq = zxrq.substring(0,4)+"-"+ zxrq.substring(4,6)+"-"+zxrq.substring(6);
        //坐诊类型
        String zzlx = mp.get("zzlx").toString();
        //诊室名称
        String pbkmmc = mp.get("pbkmmc").toString();
        //排班科目类型
        String pbkmlx = mp.get("pbkmlx").toString();
        //价格
        String xmdj = mp.get("xmdj").toString();
        //诊查费类型
        String zlfmc = mp.get("zlfmc").toString();
        //开始时间
        String kssj = mp.get("kssj").toString();
        //医院编码
        String yybm = mp.get("yybm") == null ? "03" : mp.get("yybm").toString();

        Float fee = Float.parseFloat(xmdj);

        if(pbkmmc.indexOf("急诊") != -1){
            continue;
        }
        Schedule schedule = new Schedule();

        if(mp.get("ks_mc") != null){
            String  doctorName =  mp.get("ks_mc").toString();
            if(doctorName.indexOf("广瑞路") !=-1 && doctorName.indexOf("广瑞路门诊") ==-1){
                doctorName = doctorName.replace("广瑞路","广瑞路门诊");
            }

            schedule.setDeptName(doctorName);
            schedule.setDeptId(Tools.getMD5(doctorName));
            schedule.setDoctorName(pbkmmc);
            schedule.setDoctorId(Tools.getMD5(pbkmmc));
            schedule.setRegisterType(2);

        }else{
            schedule.setDeptName(pbkmmc);
            schedule.setDeptId(Tools.getMD5(pbkmmc));
            schedule.setRegisterType(1);
        }
        SimpleDateFormat sdf =   new SimpleDateFormat( "HH:mm");

        if(sdf.parse(kssj).getTime() < sdf.parse("12:00").getTime()){
            schedule.setHalf(1);
        }else{
            schedule.setHalf(2);
        }

        schedule.setDate(zxrq);
        schedule.setRegistryFee(fee);

        String regName = zlfmc.replace("诊察费","").replace("诊查费","").replace("门诊","");
        regName =  regName.replaceAll(" +","").replaceAll("\\s*","");

        schedule.setRegisterName(regName.indexOf("副主任医师") != -1 || regName.indexOf("主任医师") != -1 ? "专家" : "普通");
        //schedule.setRegisterName(regName);

        schedule.setcTime(System.currentTimeMillis());
        schedule.setStatus(1);
        schedule.setHospital(hospital);
        if("02".equals(yybm)){
            schedule.setBranchName("广瑞路");
            schedule.setBranch("02");
        }else{
            schedule.setBranchName("安镇");
            schedule.setBranch("01");
        }

        schedules.add(schedule);
    }
    DBTools.db("basedb").addItem(schedules);
    out.println("执行完毕");
%>
